package java04;

import java.util.Objects;

class MyTime{
    int year;
    int month;
    int day;
    String name;

    public MyTime() {
    }

    public MyTime(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }
//重写equals方法
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {//两个对象保存的地址是否相同
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {//传过来的对象地址是否为空，或者两个类的类名是否不相同
            return false;
        }
        MyTime myTime = (MyTime) obj;//向下转型
        return year == myTime.year && month == myTime.month && day == myTime.day;
    }
}
public class EqualsTset01 {
    public static void main(String[] args){
        MyTime t1 = new MyTime(2008,8,8);
        MyTime t2 = new MyTime(2008,8,8);
        boolean t = t1.equals(t2);
        System.out.println(t);
    }
}
